package ttp.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import ttp.dao.TtpDAO;
import ttp.service.ChemicalService;
import ttp.service.CrushService;
import ttp.service.CuttingService;
import ttp.service.DryingService;
import ttp.service.Service;
import ttp.service.TreeService;
import ttp.to.ChemicalTO;
import ttp.to.CuttingTO;
import ttp.to.DryingTO;
import ttp.to.TreeTO;

public class TtpController extends MultiActionController{

	private CrushService crushService;
	private ChemicalService chemicalService;
	private DryingService dryingService;
	private CuttingService cuttingService;
	private TreeService treeService;
	private Service service;

	public 	TtpController(TreeService treeService, CrushService crushService, ChemicalService chemicalService, DryingService dryingService, CuttingService cuttingService, Service service){
		this.treeService = treeService;
		this.crushService = crushService;
		this.chemicalService = chemicalService;
		this.dryingService = dryingService;
		this.cuttingService = cuttingService;
		this.service = service;
	}

	public ModelAndView Tree(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;	
		TreeTO tto = treeService.run();
		int stop = service.selectTreeStop();
		HashMap map = new HashMap();
		map.put("tto", tto);
		map.put("stop",stop);
		mv = new ModelAndView("jsonView","map",map);
		return mv;
	}
	public ModelAndView Crush(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		HashMap map = crushService.run();
		int stop = service.selectCrushStop();
		map.put("stop", stop);
		mv = new ModelAndView("jsonView","map",map);
		System.out.println(map);
		return mv;
	}
	public ModelAndView Chemical(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		HashMap map = chemicalService.run();
		int stop = service.selectChemicalStop();
		map.put("stop", stop);
		mv = new ModelAndView("jsonView","map",map);
		return mv;
	}
	public ModelAndView Drying(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		HashMap map = dryingService.run();
		int stop = service.selectDryingStop();
		map.put("stop", stop);
		mv = new ModelAndView("jsonView","map",map);
		return mv;
	}
	public ModelAndView Cutting(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		HashMap map = cuttingService.run();
		int stop = service.selectCuttingStop();
		map.put("stop", stop);
		mv = new ModelAndView("jsonView","map",map);
		return mv;
	}
	//---------------------------------------
	public ModelAndView updateTreeStop0(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateTreeStop0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView updateTreeStop1(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateTreeStop1();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	//----------------------------------------
	public ModelAndView selectCrushStatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		int status = service.selectCrushStatus();
		mv = new ModelAndView("jsonView","status",status);
		return mv;
	}
	public ModelAndView updateCrushStatus0(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCrushStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView updateCrushStatus1(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCrushStatus1();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView CrushStopClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCrushStop1();
		service.updateCrushStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView CrushStartClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCrushStop0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	//-------------------------------------
	public ModelAndView selectChemicalStatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		int status = service.selectChemicalStatus();
		mv = new ModelAndView("jsonView","status",status);
		return mv;
	}
	public ModelAndView updateChemicalStatus0(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateChemicalStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView updateChemicalStatus1(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateChemicalStatus1();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView ChemicalStopClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateChemicalStop1();
		service.updateChemicalStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView ChemicalStartClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateChemicalStop0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	//-----------------------------------
	public ModelAndView selectDryingStatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		int status = service.selectDryingStatus();
		mv = new ModelAndView("jsonView","status",status);
		return mv;
	}
	public ModelAndView updateDryingStatus0(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateDryingStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView updateDryingStatus1(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateDryingStatus1();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView DryingStopClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateDryingStop1();
		service.updateDryingStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView DryingStartClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateDryingStop0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	//---------------------------------
	public ModelAndView selectCuttingStatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		int status = service.selectCuttingStatus();
		mv = new ModelAndView("jsonView","status",status);
		return mv;
	}
	public ModelAndView updateCuttingStatus0(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCuttingStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView updateCuttingStatus1(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCuttingStatus1();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView CuttingStopClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCuttingStop1();
		service.updateCuttingStatus0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
	public ModelAndView CuttingStartClick(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = null;
		service.updateCuttingStop0();
		mv = new ModelAndView("jsonView");
		return mv;
	}
}
